Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageNum: 1,        
    dataList: [],     
    pageTotal: 0,      
  },

  /**
   * 获取数据的核心方法
   */
  getData() {
    wx.showLoading({
      title: '数据正在加载',
    });
    wx.request({
      url: 'http://localhost:8080/announcementConsult/page', 
      data: {
        channelId: 409,
        pageNum: this.data.pageNum,  
        pageSize: 15,               
      },
      method: 'GET',
      success: (resp) => {
        console.log("当前请求页码：", this.data.pageNum);
        console.log("后端返回数据：", resp.data);

        const totalPage = resp.data.data.pageTotal || 0; 

        const currentPageData = resp.data.data.list || [];

        this.setData({
          dataList: this.data.dataList.concat(currentPageData),
          pageTotal: totalPage  
        });
      },
      complete: () => {
        wx.hideLoading();      
        wx.stopPullDownRefresh(); 
      }
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getData(); 
  },

  
  onPullDownRefresh() {
    this.setData({
      pageNum: 1,        
      dataList: [],     
      pageTotal: 0,      
    }, () => {
      this.getData();    
    });
  },

  /**
   * 上拉触底：加载下一页
   */
  onReachBottom() {
    
    if (this.data.pageNum >= this.data.pageTotal) {
      wx.showToast({
        title: '已经到达最底部啦!',
        icon: 'none'
      });
      return;
    }
    
    this.setData({
      pageNum: this.data.pageNum + 1
    }, () => {
      this.getData(); 
    });
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return {
    
    };
  }
});